package demo.genericity.generator;

import interfaces.myself.Generator;

import java.util.Iterator;
import java.util.Random;

/**
 * 咖啡生成器
 *
 * @author sun.ye
 * @since 2020-07-05 20:05
 */
public class CoffeeGenerator implements Generator<Coffee> {

    private Class[] types = { Latte.class, MoCha.class, Cappuccino.class, Americano.class, Breve.class};
    private static Random random = new Random(47);
    private int size = 0;

    public CoffeeGenerator() {
    }

    public CoffeeGenerator(int size) {
        this.size = size;
    }

    @Override
    public Coffee next() {
        try{
            return (Coffee)types[random.nextInt(types.length)].newInstance();
        } catch (Exception e) {
            throw new RuntimeException();
        }
    }

}